import pymysql


class Db:
    def __init__(self):
        self.conn = pymysql.connect(host='localhost', port=3306, user='root', password='1201', db='shop',
                                    charset='utf8', cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()

    def use_db(self, sql):
        self.cursor.execute(sql)
        self.conn.commit()

    def findall(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res
    def findone(self, sql):
        self.cursor.execute(sql)
        res = self.cursor.fetchone()
        return res

datab = Db()
